<?php
/**
 * 基类
 * User: Robin
 * Date: 2019/11/11 0011
 * Email: 704289189@qq.com
 **/


namespace app\admin;


use app\common\controller\BaseController;
use app\common\service\JsonService;

class Basic extends BaseController
{
    /**
     * 操作失败提示框
     * @param string $msg
     * @param int $backUrl
     * @param string $info
     * @param int $duration
     * @return mixed
     */
    protected function faildNotice($msg = '操作失败',$backUrl = 0, $info = '', $duration = 3){
        $type = 'error';
        $this->assign(compact('msg','backUrl','info','duration','type'));
        return $this->fetch('public/notice');
    }

    /**
     * 失败提示一直持续
     * @param string $msg
     * @param int $backUrl
     * @param string $info
     * @return mixed
     */
    protected function faildNoticeLast($msg = '操作失败',$backUrl = 0,$info = ''){
        return $this->faildNotice($msg,$backUrl,$info,0);
    }

    /**
     * 操作成功提示
     * @param string $msg
     * @param int $backUrl
     * @param string $info
     * @param int $duration
     * @return mixed
     */
    protected function successfulNotice($msg = '操作成功',$backUrl = 0, $info = '', $duration = 3){
        $type = 'success';
        $this->assign(compact('msg','backUrl','info','duration','type'));
        return $this->fetch('public/notice');
    }

    /**
     * 操作成功一直提示
     * @param string $msg
     * @param int $backUrl
     * @param string $info
     * @return mixed
     */
    protected function successfulNoticeLast($msg = '操作成功',$backUrl = 0, $info = ''){
        return $this->successfulNotice($msg,$backUrl,$info,0);
    }
    /**
     * 错误提醒页面
     * @param string $msg
     * @param int $url
     */
    protected function failed($msg = 'Sorry...亲...您访问的页面出现错误', $url = 0){
        if ($this->request->isAjax()){
            exit(JsonService::fail($msg,$url)->getcontent());
        }else{
            $this->assign(compact('msg','url'));
            exit($this->fetch('public/error'));
        }
    }

    /**
     * 页面成功提示
     * @param $msg
     * @param int $url
     */
    protected function successful($msg,$url=0){
        if ($this->request->isAjax()){
            exit(JsonService::successful($msg,$url)->getContent());
        }else{
            $this->assign(compact('msg','url'));
            exit($this->fetch('public/success'));
        }
    }

    /**
     * 异常抛出
     * @param string $msg
     */
    protected function exception($msg='无法打开页面'){
        $this->assign(compact('msg'));
        exit($this->fetch('public/exception'));
    }

    /**
     * 找不到页面
     * @param $name
     */
    public function _empty($name){
        exit($this->fetch('public/404'));
    }
}